<template>
  <div style="height:100%;width:100%;position:relative;">
      <div class="pagetop">
          <template>
              <div style="width:100%;">
                  <div style="float:left;width:50%">
                      <table style="font-size:12px" class="table1style">
                          <tr>
                              <td>快速查询</td>
                              <td>
                                  <el-input v-model="txtsearch" placeholder="组合项目代码|名称|描述" style="width:200px"></el-input>
                              </td>
                          </tr>
                      </table>
                  </div>
                  <div style="float:left;width:50%;">
                      <table style="float:right">
                          <tr>
                              <td>
                                  <el-button @click="get_maindata" icon="el-icon-search" type="primary" v-has="'PINQUERY'">查询</el-button>
                                  <el-button icon="el-icon-plus" @click="comb_addEvent" v-has="'PADD'">新增</el-button>
                                  <el-button icon="el-icon-edit" @click="comb_editEvent" v-has="'PMODIFY'">修改</el-button>
                                  <el-button icon="el-icon-delete" @click="comb_delEvent" v-has="'PDELETE'">删除</el-button>
                              </td>
                          </tr>
                      </table>
                  </div>
              </div>
          </template>
      </div>
      <div class="pagecenter">
          <div class="middle-center" style="height:100%;">
              <vxe-table :data.sync="list" :loading="combitem_loading" :select-config="{reserve: true}" :sort-config="{trigger: 'cell'}" border height="auto" highlight-current-row highlight-hover-column highlight-hover-row how-header-overflow ref="combitem_table" resizable show-overflow size="mini" stripeshow-header-overflow :optimization="{animat: false}" :row-class-name="rowClassName1" @current-change="combitem_table_changeEvent" header-align="center">
                  <vxe-table-column type="selection" align="center" width="40" header-align="center"></vxe-table-column>
                  <vxe-table-column field="req_itemcode" sortable title="组合项目代码" width="130" show-overflow header-align="center"></vxe-table-column>
                  <vxe-table-column field="req_itemname" sortable title="组合项目名称" width="160" show-overflow header-align="center"></vxe-table-column>
                  <vxe-table-column field="detail_count" sortable title="子项目数" width="100" show-overflow header-align="center" align="center"></vxe-table-column>
                  <vxe-table-column field="item_price" sortable title="总价" width="100" show-overflow header-align="center" align="right"></vxe-table-column>
                  <vxe-table-column field="hospitalname" sortable title="所属医院" width="240" show-overflow header-align="center" align="center"></vxe-table-column>
                  <vxe-table-column field="description" sortable title="描述" width="200" show-overflow header-align="center"></vxe-table-column>
              </vxe-table>
          </div>
          <div class="middle-right">
              <div style="position:absolute;width:100%;height:197px;border:solid 1px #ccc;padding:2px 9px 2px 9px">
                  <table>
                      <tr>
                          <td style="width:30px;">
                              <font color="#F56C6C">组合项目</font>
                          </td>
                          <td>
                              <rm-ddl-common ref="txtreqitem" @change="reqitem_changeEvent" datatype="reqitem" dataname="申请项目" v-model="combitem_data_oldinfo.req_itemcode" :disabled=true width="265px"></rm-ddl-common>
                          </td>
                          <td>
                              项目代码
                          </td>
                          <td>
                              <el-input style="width:265px;" v-model="combitem_data_oldinfo.req_itemcode" :disabled=true></el-input>
                          </td>
                      </tr>
                      <tr>
                          <td style="width:30px;">
                              子项目数
                          </td>
                          <td>
                              <el-input style="width:265px;" v-model="combitem_data_oldinfo.detail_count" :disabled=true></el-input>
                          </td>
                          <td>
                              单价
                          </td>
                          <td>
                              <el-input style="width:265px;" v-model="combitem_data_oldinfo.item_price" :disabled=true></el-input>
                          </td>
                      </tr>
                      <tr>
                          <td colspan="4">
                              <el-input type="textarea" style="width:642px;" height="100px" placeholder="请输入描述" v-model="combitem_data_oldinfo.description" :autosize="{ minRows: 6, maxRows: 6}" :disabled=true></el-input>
                          </td>
                      </tr>
                  </table>
              </div>
              <div style="position:absolute;width:100%;height:36px;line-height:36px;text-align:right; top:200px;">
                  <el-button icon="el-icon-plus" @click="detail_addEvent">新增明细</el-button>
                  <el-button icon="el-icon-delete" @click="detail_delEvemt">删除明细</el-button>
                  <el-button icon="el-icon-document" @click="detail_saveEvent">保存明细</el-button>
              </div>
              <div style="position:absolute;top:238px; width:100%;bottom:0px;" class="detailxTable">
                  <vxe-table :data.sync="detail_data" :loading="detail_loading" :select-config="{reserve: true}" :sort-config="{trigger: 'cell'}" border height="auto" highlight-current-row highlight-hover-column highlight-hover-row how-header-overflow ref="detail_table" resizable show-overflow size="mini" stripeshow-header-overflow :optimization="{animat: false}" :edit-changing="detail_table_editchange" :edit-rules="detail_table_validRules" :edit-config="{trigger: 'click', mode: 'cell',showStatus:true}" :row-class-name="detail_rowclass">
                      <vxe-table-column type="selection" align="center" width="35"></vxe-table-column>
                      <vxe-table-column field="req_itemname" sortable title="组合项目名称" width="160" show-overflow> <template v-slot:header="{column}">
                              <span style="color:#F56C6C;">组合项目名称</span>
                          </template></vxe-table-column>
                      <vxe-table-column key="req_detailitemcode" field="req_detailitemcode" title="项目名称" width="220px">
                          <template v-slot:header="{column}">
                              <span style="color:#F56C6C;">项目名称</span>
                          </template>
                          <template v-slot="{ row,rowIndex }">
                              <rm-ddl-common @change="deyail_reqitem_changeEvent(row);" datatype="reqitem" dataname="申请项目" v-model="row.req_detailitemcode" width="200px"></rm-ddl-common>
                          </template>
                      </vxe-table-column>
                      <vxe-table-column field="req_detailitemcode" sortable title="项目代码" width="130" show-overflow></vxe-table-column>
                      <vxe-table-column key="optional" field="optional" title="可选" width="50px" align="center">
                          <template v-slot="{ row, rowIndex, columnIndex }">
                              <div :key="row.rpt_itemcode+row.req_detailitemcode+rowIndex+columnIndex" v-if="row.optional == '1'">
                                  <el-checkbox checked @change="optionalChange(row)"></el-checkbox>
                              </div>
                              <div :key="row.rpt_itemcode+row.req_detailitemcode+rowIndex+columnIndex" v-else>
                                  <el-checkbox @change="optionalChange(row)"></el-checkbox>
                              </div>
                          </template>
                      </vxe-table-column>
                      <vxe-table-column field="seq" sortable title="序号" width="50" show-overflow></vxe-table-column>
                      <vxe-table-column field="req_groupname" sortable title="分单类别" width="120" show-overflow></vxe-table-column>
                      <vxe-table-column field="qty" sortable title="数量" width="80" :edit-render="{name: 'input'}" show-overflow></vxe-table-column>
                      <vxe-table-column field="price" sortable title="单价" width="80" show-overflow></vxe-table-column>
                  </vxe-table>
              </div>
          </div>
      </div>
      <el-dialog v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" :title="combdialog_title" :visible.sync="combdialog_flag" width="560px">
          <table>
              <tr>
                  <td style="width:30px;">
                      <font color="#F56C6C">组合项目</font>
                  </td>
                  <td>
                      <rm-ddl-common ref="txtreqitem" @change="reqitem_changeEvent" datatype="reqitem" dataname="申请项目" v-model="combitem_data_info.req_itemcode" width="200px"></rm-ddl-common>
                  </td>
                  <td>
                      项目代码
                  </td>
                  <td>
                      <el-input style="width:100px;" v-model="combitem_data_info.req_itemcode" :disabled=true></el-input>&nbsp;
                      <el-button icon="el-icon-document" @click="openhisdialog_clickEvent">HIS套餐</el-button>
                  </td>
              </tr>
              <tr>
                  <td style="width:30px;">
                      子项目数
                  </td>
                  <td>
                      <el-input style="width:200px;" v-model="combitem_data_info.detail_count" :disabled=true></el-input>
                  </td>
                  <td>
                      单价
                  </td>
                  <td>
                      <el-input style="width:200px;" v-model="combitem_data_info.item_price" :disabled=true></el-input>
                  </td>
              </tr>
              <tr>
                  <td colspan="4">
                      <el-input type="textarea" style="width:512px;" height="100px" placeholder="请输入描述" v-model="combitem_data_info.description" :autosize="{ minRows: 4, maxRows: 4}"></el-input>
                  </td>
              </tr>
              <tr>
                  <td colspan="4">
                      <div style="height:200px;width:512px;">
                          <vxe-table :data.sync="his_detail_data" :select-config="{reserve: true}" :sort-config="{trigger: 'cell'}" border height="auto" highlight-current-row highlight-hover-column highlight-hover-row how-header-overflow ref="dialogdetail_table" resizable show-overflow size="mini" stripeshow-header-overflow :optimization="{animat: false}" :row-class-name="detail_rowclass">
                              <vxe-table-column type="selection" align="center" width="40"></vxe-table-column>
                              <vxe-table-column field="req_itemname" sortable title="组合项目名称(HIS套餐)" width="160" show-overflow></vxe-table-column>
                              <vxe-table-column key="req_detailitemcode" field="req_detailitemcode" title="项目名称(HIS套餐)" width="220px">
                                  <template v-slot="{ row,rowIndex }">
                                      <rm-ddl-common datatype="reqitem" dataname="申请项目" v-model="row.req_detailitemcode" width="200px" :disabled=true></rm-ddl-common>
                                  </template>
                              </vxe-table-column>
                              <vxe-table-column key="optional" field="optional" title="可选" width="50px" align="center">
                                  <template v-slot="{ row, rowIndex, columnIndex }">
                                      <div :key="row.rpt_itemcode+row.req_detailitemcode+rowIndex+columnIndex" v-if="row.optional == '1'">
                                          <el-checkbox checked disabled></el-checkbox>
                                      </div>
                                      <div :key="row.rpt_itemcode+row.req_detailitemcode+rowIndex+columnIndex" v-else>
                                          <el-checkbox disabled></el-checkbox>
                                      </div>
                                  </template>
                              </vxe-table-column>
                              <vxe-table-column field="qty" sortable title="数量" width="80" show-overflow></vxe-table-column>
                              <vxe-table-column field="price" sortable title="单价" width="80" show-overflow></vxe-table-column>
                          </vxe-table>
                      </div>
                  </td>
              </tr>
              <tr>
                  <td colspan="4">
                      <div style="width:100%;float:left;">
                          <div style="width:50%;text-align:left;float:left;">
                              <el-button icon="el-icon-delete" @click="dialogdetail_delEvemt">删除HIS套餐内申请项目</el-button>
                          </div>
                          <div style="width:50%;text-align:right;float:left;">
                              <el-button @click="combdialog_saveEvent">保存</el-button>
                              <el-button @click="combdialog_cancelEvent">取消</el-button>
                          </div>
                      </div>
                  </td>
              </tr>
          </table>
      </el-dialog>
      <el-dialog v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" title="HIS套餐" :visible.sync="hisdialog_flag">
          <table>
              <tr>
                  <td>
                      <div style="float:left;width:100%;">
                          <div style="float:left;text-align:left;width:50%;">
                              <el-input style="width:200px;" v-model="hisdialog_selstr" placeholder="输入查询内容" @keyup.enter.native="dialoghis_seachEvent"></el-input>
                          </div>
                          <div style="float:left;text-align:right;width:50%;">
                              <font style="font-size:14px;" color="#F56C6C">注：禁用条目数据为未添加的项目！</font>
                          </div>
                      </div>
                  </td>
              </tr>
              <tr>
                  <td>
                      <div style="height:400px;width:685px;margin-top:5px;">
                          <vxe-table :data.sync="his_data" :loading="his_loading" :select-config="{reserve: true}" :sort-config="{trigger: 'cell'}" border height="auto" highlight-current-row highlight-hover-column highlight-hover-row how-header-overflow ref="his_table" resizable show-overflow size="mini" stripeshow-header-overflow :optimization="{animat: false}" :span-method="his_rowspanmethod" @cell-dblclick="his_celldbclickEvent" :row-class-name="his_rowclass">
                              <vxe-table-column field="combitemcode" title="套餐代码" width="80px" sortable></vxe-table-column>
                              <vxe-table-column field="combitemname" title="套餐名称" width="150px" sortable></vxe-table-column>
                              <vxe-table-column field="detailitemcode" title="明细项目代码" width="120px" sortable></vxe-table-column>
                              <vxe-table-column field="detailitemname" title="明细项目名称" width="150px" sortable></vxe-table-column>
                              <vxe-table-column field="seq" title="序号" width="80px" sortable></vxe-table-column>
                              <vxe-table-column field="qty" title="数量" width="80px" sortable></vxe-table-column>
                          </vxe-table>
                      </div>
                  </td>
              </tr>
          </table>
      </el-dialog>
  </div>
</template>

<script>
// import { Promise } from "q";
import XE from "xe-utils"; //引入工具类
export default {
  name: "MNG233",
  data() {
      return {
          txtsearch: "",
          combitem_data: [],
          actionFlag: "M",
          combitem_loading: false,
          combitem_data_info: {},
          combitem_data_oldinfo: {},
          combdialog_title: "添加",
          combdialog_flag: false,
          hisdialog_flag: false,
          hisdialog_selstr: "",
          his_data: [],
          selrow: [],
          his_alldata: [],
          his_loading: false,
          his_detail_data: [],
          detail_data: [],
          item_dict_data: [],
          detail_loading: false,
          detail_table_validRules: {
              req_detailitemcode: [{ required: true, message: "必须填写" }],
          },
          AddData: [],
          ModData: [],
      };
  },
  created() {
      this.get_maindata();
  },
  watch: {
      txtsearch(val) {
          let row = this.list[0];
          if (row) {
              this.hightLightRow(row);
          } else {
              this.hightLightRow(false);
          }
      },
  },
  computed: {
      list() {
          let filterName = this.txtsearch.trim();
          if (filterName) {
              let rest = this.combitem_data.filter((item) => {
                  return item.req_itemcode.toUpperCase().indexOf(filterName.toUpperCase()) > -1 || (item.req_itemname ? item.req_itemname.toUpperCase().indexOf(filterName.toUpperCase()) > -1 : false) || (item.req_itemname ? item.req_itemname.toUpperCase().indexOf(filterName.toUpperCase()) > -1 : false) || (item.description ? item.description.toUpperCase().indexOf(filterName.toUpperCase()) > -1 : false);
              });
              return rest;
          } else {
              return this.combitem_data;
          }
      },
  },
  mounted() {},
  updated() {},
  methods: {
      get_maindata() {
          this.AddData = [];
          this.ModData = [];
          this.combitem_loading = true;
          this.$tool
              .request({
                  url: "MNG/MNG2/MNG233",
                  method: "post",
                  data: {
                      action: "get_maindata",
                  },
              })
              .then((res) => {
                  this.combitem_data = res.Data;
                  this.combitem_loading = false;
                  if (XE.isUndefined(this.combitem_data_oldinfo.req_itemcode)) {
                      if (this.combitem_data.length > 0) {
                          // this.combitem_table_change(this.combitem_data[0]);
                          this.combitem_data_oldinfo = XE.clone(this.combitem_data[0], true);
                          this.hightLightRow(this.combitem_data[0]);
                          //   this.selrow = row;
                          //     this.get_detaildata();
                          // this.get_detaildata();
                          // this.$refs.combitem_table.setCurrentRow(this.combitem_data[0]);
                      }
                      // } else {
                      //     XE.each(this.combitem_data, (item, key) => {
                      //         if (item.req_itemcode == this.combitem_data_oldinfo.req_itemcode) {
                      //             this.$refs.combitem_table.setCurrentRow(this.combitem_data[key]);
                      //             this.combitem_table_change(this.combitem_data[key]);
                      //             this.get_detaildata();
                      //             let that = this;
                      //             XE.delay(
                      //                 function(name) {
                      //                     that.$refs.combitem_table.scrollToRow(that.combitem_data[key]);
                      //                 },
                      //                 500,
                      //                 "test11"
                      //             );
                      //         }
                      //     });
                      // }
                  }
              })
              .catch((e) => {
                  this.$message.error(e);
              });
      },
      comb_addEvent() {
          this.actionFlag = "A";
          XE.clear(this.combitem_data_info);
          this.his_detail_data = [];
          this.combitem_data_info = {
              req_itemname: "",
              item_price: "",
              detail_count: "0",
          };
          this.combdialog_title = "添加";
          this.combdialog_flag = true;
      },
      openhisdialog_clickEvent() {
          this.hisdialog_flag = true;
          this.his_loading = true;
          this.hisdialog_selstr = "";
          this.$tool
              .request({
                  url: "MNG/MNG2/MNG233",
                  method: "post",
                  data: {
                      action: "get_his",
                      selstr: this.hisdialog_selstr,
                  },
              })
              .then((res) => {
                  this.his_data = res.Item1;
                  this.his_alldata = res.Item1; //留存全部HIS套餐数据 后面判断方便
                  this.item_dict_data = res.Item2;
                  this.his_loading = false;
              })
              .catch((e) => {
                  this.$message.error(e);
              });
      },
      dialoghis_seachEvent() {
          this.$nextTick(() => {
              this.his_loading = true;
              this.$tool
                  .request({
                      url: "MNG/MNG2/MNG233",
                      method: "post",
                      data: {
                          action: "get_his_select",
                          selstr: this.hisdialog_selstr,
                      },
                  })
                  .then((res) => {
                      this.his_data = res;
                      this.his_loading = false;
                  })
                  .catch((e) => {
                      this.$message.error(e);
                  });
          });
      },
      computesubitem() {
          //子项个数计算

          if (this.actionFlag == "A") {
              let adddetailxTabledate = this.$refs.dialogdetail_table.tableData;
              if (adddetailxTabledate != "") {
                  this.combitem_data_info.detail_count = editdetailxTabledate.length;
              } else {
                  this.combitem_data_info.detail_count = 0;
              }
          } else if (this.actionFlag == "M") {
              let editdetailxTabledate = this.$refs.detail_table.tableData;
              if (editdetailxTabledate != "") {
                  this.combitem_data_info.detail_count = editdetailxTabledate.length;
              } else {
                  this.combitem_data_info.detail_count = 0;
              }
          }
      },
      his_rowspanmethod({ row, $rowIndex, column, data }) {
          let fields = ["combitemcode"];
          let cellValue = row[column.property];
          if (cellValue && fields.includes(column.property)) {
              let prevRow = data[$rowIndex - 1];
              let nextRow = data[$rowIndex + 1];
              if (prevRow && prevRow[column.property] === cellValue) {
                  return { rowspan: 0, colspan: 0 };
              } else {
                  let countRowspan = 1;
                  while (nextRow && nextRow[column.property] === cellValue) {
                      nextRow = data[++countRowspan + $rowIndex];
                  }
                  if (countRowspan > 1) {
                      return { rowspan: countRowspan, colspan: 1 };
                  }
              }
          }
      },
      his_celldbclickEvent({ row, rowIndex, column, columnIndex }, event) {
          if (this.combdialog_title == "添加") {
              let main_itemcode = "";
              XE.each(this.item_dict_data, (item, key) => {
                  if (item.req_itemcode == row.combitemcode) {
                      main_itemcode = item.req_itemcode;
                  }
              });
              if (main_itemcode != "") {
                  //过滤所有不存在的项目 并提示 存在的项目集合在 his_detail_data 后面保存
                  XE.each(this.his_alldata, (hisitem, hiskey) => {
                      if (hisitem.combitemcode == row.combitemcode) {
                          let f_dictkey = -1;
                          XE.each(this.item_dict_data, (dictitem, dictkey) => {
                              if (dictitem.req_itemcode == hisitem.detailitemcode) {
                                  f_dictkey = dictkey;
                              }
                          });
                          if (f_dictkey >= 0) {
                              let info = {
                                  req_itemcode: row.combitemcode,
                                  req_itemname: row.combitemname,
                                  req_detailitemcode: hisitem.detailitemcode,
                                  seq: 10,
                                  price: this.item_dict_data[f_dictkey].item_price,
                                  optional: "0",
                                  qty: "1",
                              };
                              this.$refs.dialogdetail_table.insert(info);
                          } else {
                              this.$message({
                                  message: "子项目" + hisitem.detailitemcode + "不存在，无法添加此项目！",
                                  type: "warning",
                              });
                          }
                      }
                  });
                  this.combitem_data_info.req_itemcode = row.combitemcode;
                  this.hisdialog_flag = false;
              } else {
                  this.$message({
                      message: "项目" + row.combitemcode + "不存在，无法添加此套餐！",
                      type: "warning",
                  });
              }
          } else {
              //修改
              //过滤所有不存在的子项目+已添加过的子项目 并提示 存在的项目集合在 his_detail_data 后面保存
              XE.each(this.his_alldata, (hisitem, hiskey) => {
                  if (hisitem.combitemcode == row.combitemcode) {
                      let f_dictkey = -1;
                      XE.each(this.item_dict_data, (dictitem, dictkey) => {
                          if (dictitem.req_itemcode == hisitem.detailitemcode) {
                              f_dictkey = dictkey;
                          }
                      });
                      let detail_ishaven = false;
                      XE.each(this.detail_data, (detailitem, detailkey) => {
                          if (detailitem.req_detailitemcode == hisitem.detailitemcode) {
                              detail_ishaven = true;
                          }
                      });
                      let insertRecords = this.$refs.detail_table.getInsertRecords();
                      XE.each(insertRecords, (detailitem, detailkey) => {
                          if (detailitem.req_detailitemcode == hisitem.detailitemcode) {
                              detail_ishaven = true;
                          }
                      });
                      if (f_dictkey >= 0) {
                          if (!detail_ishaven) {
                              let info = {
                                  req_itemcode: this.combitem_data_info.req_itemcode,
                                  req_itemname: this.combitem_data_info.req_itemname,
                                  req_detailitemcode: hisitem.detailitemcode,
                                  seq: 10,
                                  price: this.item_dict_data[f_dictkey].item_price,
                                  optional: "0",
                                  qty: "1",
                              };
                              this.$refs.dialogdetail_table.insert(info);
                          }
                      } else {
                          this.$message({
                              message: "子项目" + hisitem.detailitemcode + "不存在，无法添加此项目！",
                              type: "warning",
                          });
                      }
                  }
              });
              this.hisdialog_flag = false;
          }
      },
      comb_editEvent() {
          this.actionFlag = "M";
          this.his_detail_data = [];
          let crow = this.$refs.combitem_table.getCurrentRow();
          if (crow) {
              XE.clear(this.combitem_data_info);
              XE.clear(this.combitem_data_oldinfo);
              this.combitem_data_info = XE.clone(crow, true);
              this.combitem_data_oldinfo = XE.clone(crow, true);
              this.combdialog_title = "修改";
              this.combdialog_flag = true;
          } else {
              this.$message({
                  message: "请选择需要修改的数据！",
                  type: "warning",
              });
          }
      },
      comb_delEvent() {
          this.actionFlag = "D";
          let removeRecords = this.$refs.combitem_table.getSelectRecords();
          if (removeRecords.length <= 0) {
              this.$message.error("请先选择数据！");
              return false;
          }
          this.$rmConfirm({
              type: "提示",
              msg: "删除操作请慎重考虑, 是否继续？",
              btn: {
                  confirmBtnText: "确定",
                  cancelBtnText: "取消",
              },
          })
              .then(() => {
                  //删除
                  this.$tool
                      .request({
                          url: "MNG/MNG2/MNG233",
                          method: "post",
                          data: {
                              action: "del_combitem",
                              removeRecords: removeRecords,
                          },
                      })
                      .then((res) => {
                          if (res == "1") {
                              this.$message({
                                  message: "删除成功！",
                                  type: "success",
                              });
                              this.actionFlag = "M";
                              this.get_maindata();
                          } else {
                              this.actionFlag = "M";
                              this.$message.error(res);
                          }
                      })
                      .catch((e) => {
                          this.$message.error(e);
                      });
              })
              .catch(() => {});
      },
      combdialog_saveEvent() {
          if (XE.isUndefined(this.combitem_data_info.req_itemcode) || this.combitem_data_info.req_itemcode == "") {
              this.$message({
                  message: "请选择组合项目！",
                  type: "warning",
              });
              return false;
          }
          let detail_insertRecords = this.$refs.dialogdetail_table.getInsertRecords();
          this.computesubitem();
          this.$tool
              .request({
                  url: "MNG/MNG2/MNG233",
                  method: "post",
                  data: {
                      action: "save_combitem",
                      data: this.combitem_data_info,
                      odata: this.combitem_data_oldinfo,
                      flag: this.combdialog_title,
                      detail_insertRecords: detail_insertRecords,
                  },
              })
              .then((res) => {
                  if (res.Item1 != "1") {
                      this.$message({
                          message: res.Item2,
                          type: "warning",
                      });
                  } else {
                      this.$message.success("保存成功！");
                      if (this.actionFlag == "A") {
                          if (this.AddData.indexOf(this.combitem_data_info.req_itemcode) == -1) this.AddData.push(this.combitem_data_info.req_itemcode);
                          console.log("combdialog_saveEvent -> this.AddData", this.AddData);
                          this.$refs.combitem_table.insert(this.combitem_data_info).then(({ row }) => {
                              this.hightLightRow(row);
                              this.combitem_data.push(row);
                          });
                      } else if (this.actionFlag == "M") {
                          if (this.ModData.indexOf(this.combitem_data_info.req_itemcode) == -1) this.ModData.push(this.combitem_data_info.req_itemcode);
                          this.SetToTable(this.combitem_data_info).then((row) => {
                              this.hightLightRow(row);
                          });
                          console.log("combdialog_saveEvent -> this.ModData", this.ModData);
                      } else {
                          this.actionindex = "M";
                      }
                      this.combdialog_flag = false;
                  }
              })
              .catch((e) => {
                  this.$message.error(e);
              });
      },
      SetToTable(obj) {
          return new Promise((s, f) => {
              this.selrow.req_itemname = obj.req_itemname;
              this.selrow.req_itemcode = obj.req_itemcode;
              this.selrow.detail_count = obj.detail_count;
              this.selrow.item_price = obj.item_price;
              this.selrow.description = obj.description;
              s(this.selrow);
              return;
          });
      },
      SetToTable2(obj) {
          console.log("obj", obj);
          return new Promise((s, f) => {
              this.selrow.detail_count = obj;
              console.log("this.selrow", this.selrow);
              s(this.selrow);
              console.log("SetToTable -> this.selrow", this.selrow);
              return;
          });
      },
      async hightLightRow(row) {
          if (!!row) {
              this.$refs.combitem_table.setCurrentRow(row);
              this.$refs.combitem_table.scrollToRow(row);
              this.combitem_data_oldinfo = XE.clone(row, true);
              await this.get_detaildata(row);
          } else {
              this.$refs.combitem_table.setCurrentRow(null);
              this.combitem_data_oldinfo = {};
              // this.tempbact_testgroup = {};
              this.detail_data = [];
          }
      },
      combdialog_cancelEvent() {
          this.combdialog_flag = false;
      },
      dialogdetail_delEvemt() {
          let removeRecords = this.$refs.dialogdetail_table.getSelectRecords();
          if (removeRecords.length <= 0) {
              this.$message.error("请先选择数据！");
              return false;
          }
          this.$rmConfirm({
              type: "提示",
              msg: "删除操作请慎重考虑, 是否继续？",
              btn: {
                  confirmBtnText: "确定",
                  cancelBtnText: "取消",
              },
          })
              .then(() => {
                  this.$refs.dialogdetail_table.removeSelecteds();
              })
              .catch(() => {});
      },
      reqitem_changeEvent(code, name) {
          this.combitem_data_info.req_itemname = name;
          this.$nextTick(() => {
              this.$tool
                  .request({
                      url: "MNG/MNG2/MNG233",
                      method: "post",
                      data: {
                          action: "get_dictprice",
                          itemcode: code,
                      },
                  })
                  .then((res) => {
                      this.combitem_data_info.item_price = res;
                  })
                  .catch((e) => {
                      this.$message.error(e);
                  });
              this.combitem_data_info.req_itemcode = code;
          });
      },
      deyail_reqitem_changeEvent(row) {
          this.$nextTick(() => {
              XE.each(this.detail_data, (item, key) => {
                  if (item.req_detailitemcode == row.req_detailitemcode) {
                      this.$message({
                          message: "申请项目重复！",
                          type: "warning",
                      });
                      row.req_detailitemcode = "";
                      return false;
                  }
              });
              let insertRecords = this.$refs.detail_table.getInsertRecords();
              XE.each(insertRecords, (item, key) => {
                  if (item.req_detailitemcode == row.req_detailitemcode && row._XID != item._XID) {
                      this.$message({
                          message: "申请项目重复！",
                          type: "warning",
                      });
                      row.req_detailitemcode = "";
                      return false;
                  }
              });
              this.$tool
                  .request({
                      url: "MNG/MNG2/MNG233",
                      method: "post",
                      data: {
                          action: "get_dictprice",
                          itemcode: row.req_detailitemcode,
                      },
                  })
                  .then((res) => {
                      row.price = res;
                  })
                  .catch((e) => {
                      this.$message.error(e);
                  });
          });
      },
      // combitem_table_changeEvent({ row, rowIndex, column, columnIndex }, event) {
      //     this.combitem_table_change(row);
      //     this.get_detaildata();
      // },
      async combitem_table_changeEvent({ row }) {
          this.combitem_data_oldinfo = XE.clone(row, true);

          await this.get_detaildata(row);
      },
      get_detaildata(row) {
          this.selrow = row;
          this.detail_loading = true;
          this.$tool
              .request({
                  url: "MNG/MNG2/MNG233",
                  method: "post",
                  data: {
                      action: "get_combdetail",
                      itemcode: row.req_itemcode,
                  },
              })
              .then((res) => {
                  this.detail_data = res.Data;
                  this.detail_loading = false;
              })
              .catch((e) => {
                  this.$message.error(e);
              });
      },
      // combitem_table_change(row) {
      //     this.combitem_data_oldinfo = XE.clone(row, true);
      //     this.selrow = row;
      // },
      optionalChange(row) {
          if (row.optional == "1") {
              row.optional = "0";
          } else if (row.optional == "0") {
              row.optional = "1";
          } else {
              row.optional = "1";
          }
      },
      detail_table_editchange(obj) {
          let o_str = obj.old; //修改前字符串
          let n_str = obj.new; //修改后字符串
          let columnName = obj.p.column.property;
          if (columnName == "qty") {
              return this.$tool.onlyNumber(n_str);
          } else {
              return n_str;
          }
      },
      detail_addEvent() {
          let maxseq = 10; //默认10
          let o_seq = 0;
          let n_seq = 0;
          let insertRecords = this.$refs.detail_table.getInsertRecords();
          XE.each(this.detail_data, (item, key) => {
              if (Number(item.seq) > o_seq) {
                  o_seq = Number(item.seq);
              }
          });
          XE.each(insertRecords, (item, key) => {
              if (Number(item.seq) > n_seq) {
                  n_seq = Number(item.seq);
              }
          });
          if (o_seq > n_seq) {
              maxseq += o_seq;
          } else {
              maxseq += n_seq;
          }
          let info = {
              req_itemcode: this.combitem_data_oldinfo.req_itemcode,
              req_itemname: this.combitem_data_oldinfo.req_itemname,
              req_detailitemcode: "",
              seq: maxseq,
              price: "",
              optional: "0",
              qty: "1",
          };
          this.$refs.detail_table.insert(info);
      },
      detail_delEvemt() {
          let removeRecords = this.$refs.detail_table.getSelectRecords();
          if (removeRecords.length <= 0) {
              this.$message.error("请先选择数据！");
              return false;
          }

          this.$rmConfirm({
              type: "提示",
              msg: "删除操作请慎重考虑, 是否继续？",
              btn: {
                  confirmBtnText: "确定",
                  cancelBtnText: "取消",
              },
          })
              .then(() => {
                  this.$refs.detail_table.removeSelecteds();
              })
              .catch(() => {});
      },
      detail_saveEvent() {
          let detail_count = 0;
          this.$refs.detail_table.validate((valid) => {
              if (valid) {
                  let removeRecords = this.$refs.detail_table.getRemoveRecords();
                  let updateRecords = this.$refs.detail_table.getUpdateRecords();
                  let insertRecords = this.$refs.detail_table.getInsertRecords();
                  let detailxTabledate = this.$refs.detail_table.tableData; //子项个数计算
                  if (detailxTabledate != "") {
                      detail_count = detailxTabledate.length;
                  }
                  this.$tool
                      .request({
                          url: "MNG/MNG2/MNG233",
                          method: "post",
                          data: {
                              action: "save_detail",
                              removeRecords: removeRecords,
                              updateRecords: updateRecords,
                              insertRecords: insertRecords,
                              detail_count: detail_count,
                              req_itemcode: this.combitem_data_oldinfo.req_itemcode,
                          },
                      })
                      .then((res) => {
                          if (res == "1") {
                              this.$message({
                                  message: "保存成功！",
                                  type: "success",
                              });
                              this.selrow.detail_count = detailxTabledate.length;
                              this.combitem_data_oldinfo.detail_count = detailxTabledate.length;
                              // this.get_maindata();
                              // if (this.ModData.indexOf(this.combitem_data_info.req_itemcode) == -1) this.ModData.push(this.combitem_data_info.req_itemcode);
                              console.log("detail_saveEvent -> this.ModData", this.ModData);
                              // this.combitem_data_info.detail_count = this.detailxTabledate.detail_count;

                              // this.SetToTable2(this.detailxTabledate.detail_count).then(row => {
                              //     this.hightLightRow(row);
                              // });
                          } else {
                              this.$message.error(res);
                          }
                      })
                      .catch((e) => {
                          this.$message.error(e);
                      });
              } else {
                  this.$message.error("主键校验错误！");
                  return false;
              }
          });
      },
      //  async SaveCount(count) {
      //     try {
      //         const res = await this.$tool.request({
      //             url: "MNG/MNG2/MNG233",
      //             method: "post",
      //             data: {
      //                 action: "save_count",
      //                 count:count
      //             }
      //         });
      //     } catch (e) {
      //         this.$message.warning(e);
      //     }
      // },
      rowClassName1({ row, rowIndex }) {
          if (this.AddData.indexOf(row.req_itemcode) > -1) {
              return "row-new";
          }
          if (this.ModData.indexOf(row.req_itemcode) > -1) {
              return "row-modify";
          }
      },
      //"rm-cancel"; //作废
      //"rm-disable"; //禁用
      //"rm-readonly"; //只读
      //"rm-alert"; //警告
      detail_rowclass({ row, rowIndex }) {
          // if (row.optional != "1") {
          //     return "rm-alert";
          // }
      },
      his_rowclass({ row, rowIndex }) {
          let ishaven = false;
          XE.each(this.item_dict_data, (item, key) => {
              if (item.req_itemcode == row.combitemcode) {
                  ishaven = true;
              }
          });
          if (!ishaven) {
              return "rm-disable";
          }
      },
  },
};
</script>

<style scoped>
.pagetop {
  left: 0;
  right: 0;
  height: 36px;
  display: -webkit-box;
  -webkit-box-pack: center;
  -webkit-box-align: center;
  border: solid 1px #ccc;
  position: absolute;
  z-index: 99;
}

.pagecenter {
  position: absolute;
  top: 40px;
  width: 100%;
  left: 0;
  bottom: 0px;
  overflow: auto;
}

.middle-center {
  position: absolute;
  height: 100%;
  right: 675px;
  left: 0;
  overflow: auto;
}

.middle-right {
  position: absolute;
  top: 0;
  bottom: 0px;
  overflow: visible;
  width: 670px;
  right: 0px;
}

table tr td:nth-child(odd) {
  text-align: right;
  white-space: nowrap;
}
table tr td:nth-child(even) {
  text-align: left;
}
table tr td:nth-child(1) {
  width: 80px;
}
table {
  font-size: 12px;
  border-collapse: separate;
  border-spacing: 5px;
}
.detailxTable {
}
/deep/ tr.vxe-body--row.row-modify {
  color: blue;
}
/deep/ tr.vxe-body--row.row-new {
  color: #cc6600;
}
/deep/.detailxTable tr td div .el-input__inner {
  border: 1px solid rgba(255, 254, 254, 0) !important;
  background-color: rgba(255, 254, 254, 0) !important;
}

/deep/.el-input.is-disabled .el-input__inner {
  background-color: #f5f7fa;
  /* border-color: #E4E7ED; */
  color: #000000;
  cursor: not-allowed;
}
</style>